// pages/zx_czhi/zx_czhi.jsvar
var util = require('../../wxParse/util.js');
var utilMd5 = require('../../wxParse/md5.js');
var WxParse = require('../../wxParse/wxParse.js');
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
     
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  chongzhi:function(e){
    app.globalData.chongzhi = e.detail.value
  },
  chongzhi1:function(e){
    var that = this;
      if(app.globalData.gl_id==1){
        if(app.globalData.chongzhi==''|| app.globalData.chongzhi==null||app.globalData.chongzhi==undefined){
          wx.showModal({
            title: '',
            content: '请输入金额！',
            showCancel: false,
            success:function(res){
                  if(res.confirm){
                     
                  }else{
                     
                  }
            }
          })
        }else{
          if(app.globalData.gl_id==1){
              wx.request({
                url: app.globalData.url_l + 'api/wxpay/index', //注意改成自己的服务器请求地址哦！
                data:{
                  uid:app.globalData.uid,
                  account:app.globalData.chongzhi
                },
                method: 'POST',
                header: {
                  'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
                },
                success: function (response) {
                  console.log(response)
                  if(response.data.state=="2"){
                    wx.showModal({
                      title: '',
                      content:"支付失败！",
                      showCancel: false,
                      success:function(res){
                            if(res.confirm){
                            
                            }else{
                              
                            }
                      }
                    })
                  }else if(response.data.state=="1"){
                    wx.showModal({
                      title: '',
                      content: "余额不足！",
                      showCancel: false,
                      success:function(res){
                            if(res.confirm){
                            
                            }else{
                              
                            }
                      }
                    })
                  }else if(response.data.state=="0"){
                    wx.showModal({
                      title: '',
                      content: "未找到订单！",
                      showCancel: false,
                      success:function(res){
                            if(res.confirm){
                            
                            }else{
                              
                            }
                      }
                    })
                  }else if(response.data.state=="3"){
                    wx.showModal({
                      title: '',
                      content: "支付成功！",
                      showCancel: false,
                      success:function(res){
                            if(res.confirm){
                              wx.switchTab({
                                url: '../wode/wode',
                              })
                            }else{
                              
                            }
                      }
                    })
                  }else{
                      var timeStamp = (Date.parse(new Date()) / 1000).toString();
                      var pkg = 'prepay_id=' + response.data.prepay_id;
                      var nonceStr = response.data.nonce_str;
                      var paySign = utilMd5.hexMD5('appId=' + response.data.appid + '&nonceStr=' + nonceStr + '&package=' + pkg + '&signType=MD5&timeStamp=' + timeStamp + "&key=qwertyuiopasdfghjklzxcvbnm123456").toUpperCase();
                      wx.requestPayment({
                          'timeStamp': timeStamp,
                          'nonceStr': nonceStr,
                          'package': pkg,
                          'signType': 'MD5',
                          'paySign': paySign,
                          'success': function (res) {
                          wx.showModal({
                            title: '',
                            content: "支付成功！",
                            showCancel: false,
                            success:function(res){
                                  if(res.confirm){
                                    wx.switchTab({
                                      url: '../wode/wode',
                                    })
                                  }else{
                                      
                                  }
                            }
                          })
                          
                          }
                      });
                  }
                }
              })
            }else{
              wx.showModal({
                title: '',
                content: "只有管理员可以充值！",
                showCancel: false,
                success:function(res){
                      if(res.confirm){
        
                      }else{
                         
                      }
                }
              })
            }
        }
      }else{
        wx.showModal({
          title: '',
          content: '只有管理员可以充值!',
          showCancel: false,
          success:function(res){
                if(res.confirm){
                }else{
                   
                }
          }
        })
      }
    
   
   
    
   
 },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})